﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Views;
using XCommunity.Frames;
using XCommunity.Caching;

namespace XCommunity.Forums.Extension
{
  internal sealed class TopicExtData : IWriteBackCacheValue
  {

    public TopicExtData( int topicId, DataProvider dataProvider )
    {
      _dataProvider = dataProvider;

      TopicId = topicId;

      Visits = dataProvider.LoadVisits( TopicId );
    }



    private DataProvider _dataProvider;

    public int TopicId
    {
      get;
      private set;
    }


    public CachedCounter Visits
    {
      get;
      internal set;
    }


    #region IWriteBackCacheValue 成员

    bool IWriteBackCacheValue.WriteBack()
    {
      _dataProvider.UpdateVisits( TopicId, Visits );

      return true;
    }

    #endregion

    public object GetValue( string propertyName )
    {
      if ( propertyName == "Visits" )
        return Visits;

      return null;
    }
  }
}
